
var express = require('express');
var http = require('http');
var path = require('path');
var config = require('./config');
var router = require('./application/router');

var mongoose = require('mongoose');

var models = {
    User:     require('./application/model/user')(mongoose),
    Customer: require('./application/model/customer')(mongoose),
    Part:     require('./application/model/part')(mongoose)
    //Quote:    require('./application/model/quote')(mongoose),
};



var app = express();

app.set('port', process.env.PORT || config.port);
app.set('views', __dirname + '/');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.cookieParser(config.cookieSecret));
app.use(express.session({ secret: config.cookieSecret }));
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'extjs')));

mongoose.connect(config.dbpath, function onMongooseError(err) {
    if (err) throw err;
});

router.init(app, models);

http.createServer(app).listen(app.get('port'), function(){
    console.log("Listening on port %d，%s", app.get('port'), app.settings.env);
});
